package com.jeff.android.lab.jetpack.fragment

import android.widget.Button
import android.widget.TextView
import androidx.core.os.bundleOf
import androidx.fragment.app.setFragmentResult
import androidx.fragment.app.setFragmentResultListener
import butterknife.BindView
import butterknife.OnClick
import com.jeff.android.lab.BaseFragment
import com.jeff.android.lab.R

/**
 * @author: dingfeng
 * @date: 2021/3/2
 * @since: 1.0.0
 **/
class FragmentB : BaseFragment() {
    @BindView(R.id.tv_data)
    lateinit var tvData: TextView

    @BindView(R.id.btn_send)
    lateinit var btnSend: Button

    override fun getRootLayout(): Int {
        return R.layout.jetpack_fragment_a
    }

    @OnClick(R.id.btn_send)
    fun sendData() {
        setFragmentResult("key_data_from_b", bundleOf("data" to "I am from b"))
    }

    override fun initView() {
        setFragmentResultListener("key_data_from_a") {
            key, bundle -> tvData.text = String.format("接收数据:%s", bundle.getString("data"))
        }
    }


}